Page({
  data: {
    visitorList: [],
  },
  onLoad() {
    this.getVisitorList()
    this.limen = true
  },
  async getVisitorList(current = 1, pageSize = 5) {
    const {
      data: { rows },
      code,
      pageTotal,
    } = await wx.http.get('/visitor', { current, pageSize })
    if (code !== 10000) return wx.utils.toast('查询访客邀请记录失败')
    this.current = current += 1
    this.pageTotal = pageTotal
    this.data.visitorList.push(...rows)
    this.setData({ visitorList: this.data.visitorList })
    console.log('调接口完成')
  },
  // 触底
  bottomOut() {
    if (this.current === this.pageTotal) return wx.utils.toast('')
    wx.utils.throttle(this.getVisitorList, this.current)
  },

  // 节流函数
  // throttle(fn, model) {
  //   console.log('节流函数触发')
  //   if (this.limen) {
  //     this.limen = false
  //     setTimeout(() => {
  //       fn(model)
  //       this.limen = true
  //     }, 5000)
  //   }
  // },
  //
  goPassport(ev) {
    wx.navigateTo({
      url: '/visitor_pkg/pages/passport/index?id=' + ev.mark.id,
    })
  },
})
